package android.app.gfestival.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.app.gfestival.R;
import android.content.Context;
import android.util.Log;

public class DateTimeUtil {
	private static final String MONDAY = "Monday";
	private static final long SECONDS = 1000;
	private static final long MINUTE = SECONDS*60;
	private static final long HOURS = MINUTE*60;
	
	public static String dateToString(Date date,String format){
//		String[] lang = Locale.getISOLanguages();
//		String[] country = Locale.getISOCountries();
//		for(int i = 0; i < lang.length; i++){//doi_IS
//			System.out.println(country[i]+ "_" + lang[i]);
//		}
		SimpleDateFormat simple= new SimpleDateFormat(format, new Locale("en"));
		String convert = simple.format(date); 
		
		return convert;
	}
	
	public static Date stringToDate(String date){
		if(date == null) date="1/1/2000";	
		Log.i(MONDAY, "--->" + date);
		Date temp = new Date(date);
		return temp;
	}
	public static Date newsStringToDate(String date){
		if(date == null) date="1/1/2000";	
		Log.i(MONDAY, "--->" + date);
		Date temp = new Date(date);
		temp.setTime(temp.getTime() + HOURS*7);
		return temp;
	}
	
	public static String convertDate(String from,String to){
		return dateToString(stringToDate(from), to);
	}
	
	public static String converNewsDate(String from, String to){
		return dateToString(newsStringToDate(from), to);
	}
	public static String convertNewsDate(String from, String to){
		DateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
		Date date = new Date(from);
	    try {
			 date = formatter.parse(from);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dateToString(date, to);
	}
	
	public static String convertDay(String day, Context context){
		if(day.startsWith("Monday")){
			day = day.replace("Monday", context.getString(R.string.monday));
		}else if(day.startsWith("Tuesday")){
			day = day.replace("Tuesday", context.getString(R.string.tuesday));
		}else if(day.startsWith("Wednesday")){
			day = day.replace("Wednesday", context.getString(R.string.wednesday));
		}else if(day.startsWith("Thursday")){
			day = day.replace("Thursday", context.getString(R.string.thursday));
		}else if(day.startsWith("Friday")){
			day = day.replace("Friday", context.getString(R.string.friday));
		}else if(day.startsWith("Saturday")){
			day = day.replace("Saturday", context.getString(R.string.saturday));
		}else if(day.startsWith("Sunday")){
			day = day.replace("Sunday", context.getString(R.string.sunday));
		}
		return day;
	}
}
